<?php

/**
 * Klasa z formatkami dot. użytkownika
 *
 */
class Default_Form_Users {
	/**
	 * Generuje formatkę dla rejestracji
	 *
	 * @return Core_Form Formatka rejestracji
	 */
	public function register() {
		$form = new Core_Form();
		
		$form->setName('registerForm')
			->setMethod(Core_Form::METHOD_POST)
			->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array()))
		
			->addElements(array(
				$form->createElement('text', 'nick')
					->setLabel('Nazwa użytkownika')
					->setRequired(true)
					->addFilter('StripTags')
					->addFilter('StringTrim')
					->setAttrib('maxlength', 32)
					->addValidator('StringLength', true, array(2, 32))
					->addValidator('Alnum', true)
					->addValidator(new Core_Validate_Exists(new Default_Model_Users(), 'nickExists'), true),
				$form->createElement('text', 'email')
					->setLabel('Adres email')
					->setRequired(true)
					->addFilter('StripTags')
					->addFilter('StringTrim')
					->setAttrib('maxlength', 64)
					->addValidator('StringLength', true, array(6, 64))
					->addValidator('EmailAddress', true)
					->addValidator(new Core_Validate_Exists(new Default_Model_Users(), 'mailExists'), true),
				$form->createElement('password', 'password')
					->setLabel('Hasło')
					->setRequired(true)
					->setAttrib('maxlength', 64)
					->addValidator('StringLength', true, array(6, 64)),
				$form->createElement('password', 'passwordRepeat')
					->setLabel('Powtórz hasło')
					->setRequired(true)
					->setAttrib('maxlength', 64)
					->addValidator('StringLength', true, array(6, 64))
					->addValidator(new Core_Validate_Password('password'), true),
				$form->createElement('checkbox', 'accept')
					->setRequired(true)
					->setOptions(array('uncheckedValue' => null))
					->setLabel(_t('Przeczytałem i akceptuję regulamin serwisu')),
				$form->createElement('checkbox', 'accept2')
					->setRequired(true)
					->setOptions(array('uncheckedValue' => null))
					->setLabel('Wyrażam zgodę na przetwarzanie moich danych osobowych zawartych w przesłanej aplikacji dla potrzeb niezbędnych do realizacji procesu rejestracji'),
				$form->createElement('captcha', 'captcha', array(
					'captcha' => 'Image',
					'captchaOptions' => array(
						'timeout' => 300,
						'imgDir' => 'images/captcha',
						'imgUrl' => Zend_Controller_Front::getInstance()->getBaseUrl() . '/images/captcha',
						'wordLen' => 4,
						'font' => '../data/fonts/cambria.ttc',
						'fontSize' => 32,
						'width' => 140,
						'height' => 70,
						'dotNoiseLevel' => 20,
						'lineNoiseLevel' => 2
					)))
					->setLabel('Wpisz kod z obrazka')
					->setAttrib('maxlength', 4),
				$form->createElement('submit', 'register')
					->setLabel('Rejestracja')
			));
		return $form;
	}
	
	/**
	 * Generuje formatkę dla przypomnienia hasła
	 *
	 * @return Core_Form Formatka logowania
	 */
	public function remind() {
		$form = new Core_Form();
		
		$form->setName('remindForm')
			->setMethod(Core_Form::METHOD_POST)
			->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array()))
			
			->addElements(array(
				$form->createElement('text', 'email')
					->setLabel('Adres email')
					->setRequired(true)
					->addFilter('StripTags')
					->addFilter('StringTrim')
					->setAttrib('maxlength', 64)
					->addValidator('StringLength', true, array(6, 64))
					->addValidator('EmailAddress', true),
				$form->createElement('captcha', 'captcha', array(
					'captcha' => 'Image',
					'captchaOptions' => array(
						'timeout' => 300,
						'imgDir' => 'images/captcha',
						'imgUrl' => Zend_Controller_Front::getInstance()->getBaseUrl() . '/images/captcha',
						'wordLen' => 4,
						'font' => '../data/fonts/cambria.ttc',
						'fontSize' => 28,
						'width' => 120,
						'height' => 50,
						'dotNoiseLevel' => 50,
						'lineNoiseLevel' => 3
					)))
					->setLabel('Wpisz kod z obrazka')
					->setAttrib('maxlength', 4),
				$form->createElement('submit', 'remind')
					->setLabel('Przypomnij hasło')
			));
		return $form;
	}
	
	/**
	 * Generuje formatkę dla logowania
	 *
	 * @return Core_Form Formatka logowania
	 */
	public function login() {
		$form = new Core_Form();
		$session = new Zend_Session_Namespace('user');
		
		$form->setName('loginForm')
			->setMethod(Core_Form::METHOD_POST)
			->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array()))
			
			->addElements(array(
				$form->createElement('text', 'email')
					->setLabel('Adres email')
					->setValue($session->email)
					->setRequired(true)
					->addFilter('StripTags')
					->addFilter('StringTrim')
					->setAttrib('maxlength', 64)
					->addValidator('StringLength', true, array(6, 64))
					->addValidator('EmailAddress', true),
				$form->createElement('password', 'password')
					->setLabel('Hasło')
					->setRequired(true)
					->setAttrib('maxlength', 64)
					->addValidator('StringLength', true, array(6, 64)),
				$form->createElement('checkbox', 'remember')
					->setLabel('Zapamiętaj mnie')
					->setChecked(true)
					->addValidator('InArray', true, array(array('0', '1'))),
				$form->createElement('submit', 'login')
					->setLabel('Zaloguj mnie')
					->addDecorator('ViewScript', array('viewScript' => 'user/_remind.phtml'))
			));
		return $form;
	}
	
	/**
	 * Generuje formatkę do drugiego kroku przypomnienia hasła (jego zmiana)
	 *
	 * @return Core_Form Formatka przypomnienia hasła
	 */
	public function remind2() {
		$form = new Core_Form();
		
		$form->setName('remindForm')
			->setMethod(Core_Form::METHOD_POST)
			->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array()))
		
			->addElements(array(
				$form->createElement('password', 'password')
					->setLabel('Nowe hasło')
					->setRequired(true)
					->setAttrib('maxlength', 64)
					->addValidator('StringLength', true, array(6, 64)),
				$form->createElement('password', 'passwordRepeat')
					->setLabel('Powtórz nowe hasło')
					->setRequired(true)
					->setAttrib('maxlength', 64)
					->addValidator('StringLength', true, array(6, 64))
					->addValidator(new Core_Validate_Password('password'), true),
				$form->createElement('submit', 'remind')
					->setLabel('Zmień hasło')
			));
		return $form;
	}
}